import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class insertJDBC {
    public static void main(String[] args) throws SQLException {
        //1.构建DataSource
        DataSource ds = new MysqlDataSource();
        ((MysqlDataSource)ds).setUrl("jdbc:mysql://127.0.0.1:3306/java110?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)ds).setUser("root");
        ((MysqlDataSource)ds).setPassword("284703");
        //2.创建连接
        Connection connection = ds.getConnection();
        //3.建立SQL
        String sql = "insert into student values(3,'轻烟')";
        PreparedStatement statement = connection.prepareStatement(sql);
        //4.执行SQL
        int n = statement.executeUpdate();
        System.out.println(n);
        //5.释放资源
        connection.close();
        statement.close();
    }
}
